package protocol.SZ_2021;

import java.util.HashMap;

public class Handle2021SZ03 implements IHandle2021SZ {
    @Override
    public String handle(SZ_2021Cmd cmd) {
        byte subOrder = cmd.subOrder();

        switch (subOrder){
            case 0x01:
                return handle0301(cmd);
            case 0x02:
                return handle0302(cmd);
            case 0x03:
                return handle0303(cmd);
            default:
                return "深标:未匹配的命令字"+(cmd.readOrder()+","+cmd.readSubOrder());
        }
    }

    private String handle0303(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:信息点播/取消");
        builder.append("\r\n");
        builder.append("信息类型:"+cmd.readInt(1));
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"取消");
        list.put(1,"点播");
        int type = cmd.readInt(1);
        builder.append("标志("+type+"):"+list.getOrDefault(type,"未定义"));
        builder.append("\r\n");
        return builder.toString();
    }


    private String handle0301(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:事件报告");
        builder.append("\r\n");
        builder.append("事件ID:"+cmd.readInt(1));
        builder.append("\r\n");
        return builder.toString();
    }


    private String handle0302(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:提问应答");
        builder.append("\r\n");
        builder.append("问题ID:"+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("答案ID:"+cmd.readInt(1));
        builder.append("\r\n");
        return builder.toString();
    }
}
